<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\EbProductLogs\model;

use app\supplyDemand\model\supplyDemand;
use app\WechatUser\model\ebWechatUser;
use plugin\saiadmin\app\model\system\SystemDictData;
use plugin\saiadmin\basic\BaseModel;

/**
 * 供需日志模型
 */
class EbProductLogs extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'log_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_product_logs';
     protected $append=[
        'type_text',

    ];
    



    /**
     * 关联模型WechatUser
     */
    public function wechatUser()
    {
        return $this->hasOne(ebWechatUser::class, 'user_id', 'user_id');
    }
     public function product()
    {
        return $this->hasOne(supplyDemand::class, 'sd_id', 'product_id');
    }
     public function searchNickNameAttr($query, $value)
    {
        $query->where('user_id', 'in', ebWechatUser::where('nickname', 'like', '%'.$value.'%')->column('user_id'));
    }
    public function searchPhoneAttr($query, $value)
    {
        $query->where('user_id', 'in', ebWechatUser::where('phone', 'like', '%'.$value.'%')->column('user_id'));
    }
    public function getTypeTextAttr($value,$data){
       
        if(isset($data['type'])){
            return    SystemDictData::where('code', 'LogType')
            ->where('value',$data['type'])->value('label');
        }
        return '';
    }
}
